Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run_until_cancelled_owned to CancellationToken #7081

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tysen
Copy link

@tysen tysen commented Jan 9, 2025

Pretty natural addition to match the cancelled_owned fn.

Motivation

let token = CancellationToken::new();
tokio::spawn(token.run_until_cancelled(my_async_fn())); // doesn't compile
tokio::spawn(async move { // current workaround
    token.run_until_cancelled(my_async_fn())).await
});
tokio::spawn(token.run_until_cancelled_owned(my_async_fn())); // compiles, looks nicer

Solution

Just a carbon copy of the existing fn switching to the appropriate cancellation future.

@tysen tysen force-pushed the add-run-until-cancelled-owned branch from 03bf4a7 to a99e2bc Compare January 9, 2025 18:49
@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync labels Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants